import { fromJS } from 'immutable';
import { GET_HOME_DATA, GET_MORE_LIST, CHANGE_SHOW_TOP } from './actionTypes';

const defaultState = fromJS({
    topicList: [],
    articlList: [],
    recommendList: [],
    listPage: 0,
    showTop: false,
})

export default (state = defaultState, action) => {
    switch (action.type) {
        case GET_HOME_DATA:
            return state.merge({
                topicList: fromJS(action.topicList),
                articlList: fromJS(action.articlList),
                recommendList: fromJS(action.recommendList),
            })
        case GET_MORE_LIST:
            return state.merge({
                articlList: state.get('articlList').concat(fromJS(action.data)),
                listPage: action.page,
            })
        case CHANGE_SHOW_TOP:
                return state.set('showTop', action.show);
        default:
            return state;
    }
}
